﻿using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace LiMinCRMPlugin
{
    [Description("批改校验单据状态（已审核不能批改）")]
    [HotUpdate]
    public class BulkEditValidateStatus : AbstractDynamicFormPlugIn
    {
        public override void OnInitialize(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.InitializeEventArgs e)
        {
            if (!(this.View.ParentFormView is IListView))
            {
                return;
            }

            ListSelectedRowCollection selectInfos = ((IListView)this.View.ParentFormView).SelectedRowsInfo;
            if (selectInfos[0].FormID == "AP_PAYBILL" || selectInfos[0].FormID== "SAL_OUTSTOCK" || selectInfos[0].FormID == "AR_RECEIVEBILL")
            {
                var statusField = this.View.ParentFormView.BillBusinessInfo.GetBillStatusField();
                string statusName = statusField.FieldName;
                foreach (var info in selectInfos)
                {
                    string status = ObjectUtils.Object2String(info.DataRow[statusName]);
                    if (string.Compare(status, "C", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        this.View.ParentFormView.ShowErrMessage("存在已审核的单据不允许批改！");
                        this.View.Close();
                    }
                }
            }
           

            base.OnInitialize(e);
        }

    }
}